import request from '@/utils/request'
// 登录功能
export const loginAPI = ({ mobile, code }) => request({
  url: '/v1_0/authorizations',
  method: 'POST',
  data: {
    mobile,
    code
  }
})

// 获取所有频道列表
export const getChannelListAPI = () => request({
  url: '/v1_0/channels'
})

// 获取用户频道列表
export const getUserChannelListAPI = () => request({
  url: '/v1_0/user/channels'
})

// 获取文章列表
export const getArticleListAPI = ({ channel_id, timestamp = new Date() }) => request({
  url: '/v1_0/articles',
  params: {
    channel_id,
    timestamp
  }
})

// 提交不喜欢的文章
export const setDisLikeArticleAPI = (artId) => request({
  url: '/v1_0/article/dislikes',
  method: 'POST',
  data: {
    target: artId
  }

})

// 举报文章
export const reportArticleAPI = ({ id, type, remark }) => request({
  url: '/v1_0/article/reports',
  method: 'POST',
  data: {
    target: id,
    type,
    remark
  }
})

// 设置更新用户选择的频道
export const setUserChannelAPI = (channels) => request({
  url: '/v1_0/user/channels',
  method: 'PUT',
  data: {
    channels
  }
})

// 删除用户频道
export const delUserChannelsAPI = (channelId) => request({
  url: `/v1_0/user/channels/${channelId}`,
  method: 'DELETE'
})

// 获取联想建议
export const getSuggestionAPI = (q) => request({
  url: '/v1_0/suggestion',
  params: {
    q
  }
})

// 获取搜索结果
export const getSearchResultAPI = ({
  page = 1, per_page = 10, q
}) => request({
  url: '/v1_0/search',
  params: {
    page,
    per_page,
    q
  }
})

// 获取文章详情
export const getArticleDetailAPI = (article_id) => request({
  url: `/v1_0/articles/${article_id}`
})

// 关注用户
export const followedUserAPI = (autId) => request({
  url: '/v1_0/user/followings',
  method: 'POST',
  data: {
    target: autId
  }
})

// 取消关注用户
export const unfollowedUserAPI = (target) => request({
  url: `/v1_0/user/followings/${target}`,
  method: 'DELETE'
})

// 点赞文章
export const articleLikeAPI = (target) => request({
  url: '/v1_0/article/likings',
  method: 'POST',
  data: {
    target: target
  }
})

// 文章-取消点赞
export const articleDisLikeAPI = (artId) => request({
  url: `/v1_0/article/likings/${artId}`,
  method: 'DELETE'
})
